package com.fast.alden.admin.web.controller.monitor;

import com.fast.alden.admin.annotation.OperationLog;
import com.fast.alden.admin.service.SysOnlineUserService;
import com.fast.alden.common.entity.vo.SysOnlineUser;
import com.fast.alden.data.model.SysOperationType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线用户管理控制器
 */
@Tag(name = "SysOnlineUserController", description = "在线用户管理")
@RestController
@RequestMapping("/online")
public class SysOnlineUserController {
    @Resource
    private SysOnlineUserService onlineUserService;

    @Operation(summary = "列表查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/list")
    public List<SysOnlineUser> list(@RequestBody @Nullable SysOnlineUser searchVo) {
        return onlineUserService.search(searchVo);
    }

    @OperationLog(title = "在线用户管理", type = SysOperationType.FORCE_LOGOUT)
    @Operation(summary = "强制退出", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/force-logout/{token}")
    public void forceLogout(@PathVariable("token") @NotNull String token) {
        onlineUserService.forceLogout(token);
    }
}
